<extend name="Base/common"/>
<block name="nav"></block>
<block name="body">
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">系统登录</h3>
                    </div>
                    <div class="panel-body">
                        <form role="form" action="__SELF__" method="post">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="请输入用户名" name="username" type="text" autofocus>
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="请输入密码" name="password" type="password">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="请输入验证码" name="verify" type="text">
                                </div>
                                <div class="form-group">
                                    <img class="verifyimg reloadverify" alt="点击切换" src="{:U('verify')}" style="cursor:pointer;">
                                </div>
                                <div class="form-group">
                                    <label>
                                        看不清点击图片刷新
                                    </label>
                                </div>
                                <div class="form-group">
                                      <div class="col-md-6 controls Validform_checktip text-warning"></div>
                                </div>
                                <!-- Change this to a button or input when using this as a form -->
                                <div class="form-group">
                                        <button type="submit" class="btn btn-lg btn-success btn-block">登录</button>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="footer"></block>

<block name="script">
    <script type="text/javascript">

        $(document)
            .ajaxStart(function(){
                $("button:submit").addClass("log-in").attr("disabled", true);
            })
            .ajaxStop(function(){
                $("button:submit").removeClass("log-in").attr("disabled", false);
            });


        $("form").submit(function(){
            var self = $(this);
            $.post(self.attr("action"), self.serialize(), success, "json");
            return false;

            function success(data){
                if(data.status){
                    window.location.href = data.url;
                } else {
                    self.find(".Validform_checktip").text(data.info);
                    //刷新验证码
                    $(".reloadverify").click();
                }
            }
        });

        $(function(){
            var verifyimg = $(".verifyimg").attr("src");
            $(".reloadverify").click(function(){
                if( verifyimg.indexOf('?')>0){
                    $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
                }else{
                    $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
            });
        });
    </script>
</block>